package com.clinic.controller;

import com.clinic.entity.Registered;
import com.clinic.service.RegisteredService;
import com.clinic.vo.ActionResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.sql.RowId;
import java.util.List;

/**
 * (Registered)表控制层
 *
 * @author makejava
 * @since 2020-11-12 15:55:22
 */
@RestController
@RequestMapping("/api")
public class RegisteredController {
    /**
     * 服务对象
     */
    @Resource
    private RegisteredService registeredService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/selectOne")
    public Registered selectOne(Integer id) {
        return this.registeredService.queryById(id);
    }


    @GetMapping("/alls")
    public ActionResult findAll(){
        List<Registered> registeredList = registeredService.findAll();
        if (registeredList!=null || registeredList.size()>0){
            return new ActionResult(200,"查询成功",registeredList);
        }
            return  new ActionResult(500,"查询失败",null);
    }
    @GetMapping("/findById")
    public ActionResult findById(int rid){
        System.out.println(rid);
        Registered reg = registeredService.findById(rid);
        if (reg!=null) {
         return new ActionResult(200,"查询成功",reg);
        }
        return new ActionResult(500,"查询失败",null);
    }
    //根据接诊表中pid得到患者信息
    @GetMapping("/findByPid")
    public ActionResult findByPid(int pid){
        Registered regbyPid = registeredService.findByPid(pid);
        if (regbyPid!=null) {
        return new ActionResult(200,"查询成功",regbyPid);
        }
        return new ActionResult(500,"查询失败",null);
    }


    //下面时模糊查询
    //通过患者姓名查询患者信息
    @GetMapping(value = "/namePatients")
    public ActionResult findByName(String pname){
        List<Registered> byName = registeredService.findByName(pname);
        if(byName!=null){
            return new ActionResult(200,"查询成功",byName);
        }
        return new ActionResult(500,"查询失败",null);
    }
    //通过接诊状态查询患者信息
    @GetMapping(value = "/statusPatients")
    public ActionResult findByStatus(Integer  rstatus){
        List<Registered> byStatus = registeredService.findByStatus(rstatus);

        if(byStatus!=null){
            return new ActionResult(200,"查询成功",byStatus);
        }
        return new ActionResult(500,"查询失败",null);
    }
}